﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyController : BaseManager<EnemyController>
{
    GameObject enmeyObj;
    Dictionary<string, GameObject> enemyDic = new Dictionary<string, GameObject>();
    public List<EnemyObject> enemyList = new List<EnemyObject>();
    Vector3 hurtVec;
    float time;
    int number = 5;
    bool isAttack;
    public EnemyController()
    {
        time = 2;
        isAttack = false;
        MonoMgr.GetInstance().AddUpdateListener(EnemyUpdateTimer);
    }



    public void CreatGameObject()
    {
        isAttack = true;
    }
    public void Recycle()
    {

        for (int i = 0; i < enemyList.Count; i++)
        {
            enemyList[i].Recycle();
        }
        number = 5;
        time = 2;
        enemyList.Clear();
    }
    int a = 0;
    void EnemyUpdateTimer()
    {
        if (GameManager.GetInstance().Game_State == E_Game_State.Play)
        {
            time = time - 0.5f * Time.deltaTime;
            if (time < 0)
            {
                a = Random.Range(0, 7);
                Vector3 newVec = new Vector3(0, 0.3f, a);
                a = Random.Range(0, 7);
                EnemyObject enemy = new EnemyObject(newVec, a);
                enemyList.Add(enemy);
                time = 2;
                number = number - 1;
            }
            if (number <= 0 && enemyList.Count <= 0)
            {
                GameManager.GetInstance().Game_State = E_Game_State.Ready;
                number = 5;
            }
        }
    }
}
